package cn.wildfire.chat.kit;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.sourcemuch.im.caiba.R;import com.sourcemuch.im.caiba.R2;

import butterknife.BindView;

public class WfcWebViewActivity extends WfcBaseActivity {
    private String url;

    @BindView(R2.id.webview)
    WebView webView;

    public static void loadUrl(Context context, String title, String url) {
        Intent intent = new Intent(context, WfcWebViewActivity.class);
        intent.putExtra("url", url);
        intent.putExtra("title", title);
        context.startActivity(intent);
    }

    @Override
    protected int contentLayout() {
        return R.layout.activity_webview;
    }

    @Override
    protected void afterViews() {
        try {
            // 设置页面字体显示
            WebSettings settings = webView.getSettings();
            settings.setUseWideViewPort(true);
            settings.setLoadWithOverviewMode(true);
            settings.setSupportZoom(true);
            settings.setDisplayZoomControls(false);
            settings.setTextZoom(200);
            url = getIntent().getStringExtra("url");
            webView.loadUrl(url);
            String title = getIntent().getStringExtra("title");
            if (TextUtils.isEmpty(title)) {
                webView.setWebViewClient(new WebViewClient() {
                    @Override
                    public void onPageFinished(WebView view, String url) {
                        super.onPageFinished(view, url);
                        String title = view.getTitle();
                        if (!TextUtils.isEmpty(title)) {
                            setTitle(title);
                        }
                    }
                });
            } else {
                setTitle(title);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
